package com.hollycrm.springframework.dbaccesslog;

import java.util.Date;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class DBAccessManagerProxyBean implements DBAccessManager {

    private Log logger = LogFactory.getLog(getClass());

    private DBAccessManager target;

    public DBAccessLog initialLog(String serviceName, String sqlText) {
        DBAccessLog log = new DBAccessLog();
        log.setServiceName(serviceName);
        log.setSqlText(sqlText);
        log.setStartTime(y2s.format(new Date()));
        return log;
    }

    public void saveLog(DBAccessLog log, boolean isComplete) {
        log.setComplete(isComplete ? "1" : "0");
        log.setEndTime(y2s.format(new Date()));
        try {
            target.saveLog(log, isComplete);
        }
        catch (Exception e) {
            logger.warn("[w] " + e.getMessage());
        }
    }

    public DBAccessManager getTarget() {
        return target;
    }
    public void setTarget(DBAccessManager target) {
        this.target = target;
    }

}
